var a = 3;
var b = 5;
a ^= b;
b ^= a;
a ^= b;
var arrs= [1,3,8];
arrs[0]^=arrs[2];
arrs[2]^=arrs[0];
arrs[0]^=arrs[2];
~~100.1324365465;//取整
//选择排序
var arr = [23312,43,3,5,546,65,657,43,435,3423,65,765,87,7];
for(var j = 0;j<arr.length;j++){
  var index = j;
  for(var i = j;i<arr.length;i++){
    if(arr[i]<arr[index]){
      index = i;
    }
  }
 if(index !== j){
   arr[j]^=arr[index];
   arr[index]^=arr[j];
   arr[j]^=arr[index];
 }
}
//给定一个数组arr,和一个数num,请把小于等于num的数放在数组的左边，大于num的数放在数组的右边。要求:只能在原数组上操作，并且只得循环一遍数组。
var arr1 = [312,421,545,5,4,65,54,6,54,234,556766,4,87];
var num = 100; //界定值
var index = -1;
for(var i = 0;i<arr1.length;i++){
  if(arr[i]<num){
    index++;
    if(i !== index){
      var c = arr1[index];
      arr1[index]=arr1[i];
      arr1[i] =c;
      // arr1[i]^=arr1[index];
      // arr1[index]^=arr1[i];
      // arr1[i]^=arr1[index];
    }
  }
}

var a = [1,3,5,9,12,23,34,45,56,67,77,111,222,333];
var b = [2,7,12,22,23,26,70,90,100];
var res = [];
function f(a,b) {
  var akey = 0;
  var bkey = 0;
 while (akey!== a.length && bkey!== b.length){
    if(a[akey] < b[bkey]){
      res.push(a[akey]);
      akey++;
    }else if(a[akey] === b[bkey]){
      res.push(a[akey]);
      res.push(b[bkey]);
      akey++;
      bkey++;
    }else{
      res.push(b[bkey]);
      bkey++;
    }
 }
 if(akey === a.length){
   for(var i = bkey;i<b.length;i++){
     res.push(b[i]);
   }
 }
 if(bkey === b.length){
    for(var j = akey;j<a.length;j++){
      res.push(a[j]);
    }
  }
}

//二叉树【完全二叉树，满二叉树】 堆排  heap stack
//冒泡排序
var arr = [5,4,3,2,1];
var n = arr.length-1; //4
for(var i = 0;i< n;i++){ //0 //1 //2 //3
  for( j = 0;j<n-i;j++){ //0 //1 //2
    if(arr[j]>arr[j+1]){
      arr[j]^=arr[j+1];
      arr[j+1]^=arr[j];
      arr[j]^=arr[j+1]; //[4,3,2,5,1]
    }
  }
}


